using System;

namespace Laba3
{
    public class Simpson
    {
        public static int Meu = 15;

        public static double Qn(double a, double b, int n){
            var result = 0d;
            for (int i = 1; i<=n/2; i++)
            {
                result += Function.FunctionValue(a + (b - a) * (2 * i + 1) / n);
            }
            result *= n * 0.5;
            return result;
        }

        public static double R2(double a, double b){
            return ((1d / 6)*(Function.FunctionValue(a) + Function.FunctionValue(b)));
        }

        public static double Rn(double a, double b, int n){
            if (n == 2) return 0.5*R2(a,b) + (1/6)*Qn(a,b,n/2);
            return 0.5*Rn(a,b,n/2) + (1/6)*Qn(a,b,n/2);
        }

        public static double Jn(double a, double b, int n){
            return (b - a)*(Rn(a, b, n) + (2/3)*Qn(a, b, n));
        }
    }
}

